import { IPSControl } from '../ipscontrol';
import { IPSDBAppMenuPortletPart } from './ipsdbapp-menu-portlet-part';
import { PSDBPortletPartImpl } from './psdbportlet-part-impl';
import { IPSSysPFPlugin } from '../../res/ipssys-pfplugin';

export class PSDBAppMenuPortletPartImpl extends PSDBPortletPartImpl implements IPSDBAppMenuPortletPart {
  get aMListStyle(): string {
    return this.M.aMListStyle;
  }

  protected ampssyspfplugin: IPSSysPFPlugin | null = null;

  getAMPSSysPFPlugin(): IPSSysPFPlugin | null {
    if (this.ampssyspfplugin != null) return this.ampssyspfplugin;
    const value = this.M.getAMPSSysPFPlugin;
    if (value == null) {
      return null;
    }
    this.ampssyspfplugin = this.getPSModel4('res.IPSSysPFPlugin', value, 'getAMPSSysPFPlugin') as IPSSysPFPlugin;
    return this.ampssyspfplugin;
  }

  get aMPSSysPFPlugin(): IPSSysPFPlugin | null {
    return this.getAMPSSysPFPlugin();
  }

  getAMPSSysPFPluginMust(): IPSSysPFPlugin {
    const value = this.getAMPSSysPFPlugin();
    if (value == null) {
      throw new Error('未指定应用菜单绘制插件');
    }
    return value;
  }

  get codeName(): string {
    return this.M.codeName;
  }

  protected contentpscontrol: IPSControl | null = null;

  getContentPSControl(): IPSControl | null {
    if (this.contentpscontrol != null) return this.contentpscontrol;
    const value = this.M.getContentPSControl;
    if (value == null) {
      return null;
    }
    this.contentpscontrol = this.findPSControl(value);
    return this.contentpscontrol;
  }

  get contentPSControl(): IPSControl | null {
    return this.getContentPSControl();
  }

  getContentPSControlMust(): IPSControl {
    const value = this.getContentPSControl();
    if (value == null) {
      throw new Error('未指定内容部件');
    }
    return value;
  }

  get portletType(): 'LIST' | 'CHART' | 'VIEW' | 'HTML' | 'TOOLBAR' | 'ACTIONBAR' | 'CUSTOM' | 'APPMENU' | 'CONTAINER' | 'RAWITEM' {
    return this.M.portletType;
  }

  get title(): string {
    return this.M.title;
  }

  get cls(): string {
    return 'PSDBAppMenuPortletPartImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.dashboard.IPSDBAppMenuPortletPart') return true;
    return super.instanceof(cls);
  }
}
